<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="inc/taglibs.jsp" %>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <%@ include file="inc/meta.jsp" %>
    <meta name="description" content="">
    <meta name="author" content="">
    <title>反馈问题列表</title>
    <%@ include file="inc/css.jsp" %>
</head>

<body>
<div id="posts" class="wrapper">

    <%@ include file="inc/nav.jsp" %>

    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h1 class="page-header">反馈问题管理</h1>
            </div>
            <!-- /.col-lg-12 -->
        </div>

        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <a href="admin/question/show" class="btn btn-outline btn-primary btn-lg" role="button">添加反馈问题</a>
                        <a href="javascript:void(0)" onclick="_questionList.fn.toDownloadExcel()" class="btn btn-outline btn-info btn-lg" role="button">导出EXCEL</a>
                        <a href="javascript:void(0)" onclick="_questionList.fn.clickFire()" class="btn btn-outline btn-info btn-lg" role="button">导入EXCEL</a>

                        <form class="navbar-form navbar-right" role="search">
                            <div class="form-group">
                                <label>分类：</label>
                                <select id="typeList" style="width: 120px;" class="form-control">
                                    <option value="">全部</option>
                                    <option value="1">安全问题</option>
                                    <option value="2">6S问题</option>
                                </select>
                            </div>
                            <button type="button" id="c_search" class="btn btn-primary btn-sm">搜索</button>
                        </form>
                    </div>
                    <!-- /.panel-heading -->
                    <div class="panel-body">

                        <div class="table-responsive">

                            <table class="table table-striped table-bordered table-hover" id="dataTables">
                                <colgroup>
                                    <col class="gradeA even" style="width: 2%"/>
                                    <col class="gradeA odd"/>
                                    <col class="gradeA even"/>
                                    <col class="gradeA odd"/>
                                    <col class="gradeA even"/>
                                    <col class="gradeA odd" style="width: 5%"/>
                                    <col class="gradeA even"/>
                                    <col class="gradeA odd"/>
                                    <col class="gradeA even" style="width: 5%"/>
                                    <col class="gradeA odd" style="width: 5%"/>
                                    <col class="gradeA even" style="width: 10%"/>
                                </colgroup>
                                <thead>
                                <tr>
                                    <th>编号</th>
                                    <th>问题分类</th>
                                    <th>记录日期</th>
                                    <th>区域/工段</th>
                                    <th>风险描述</th>
                                    <th>问题描述得分</th>
                                    <th>问题反馈人姓名</th>
                                    <th>问题反馈人部门</th>
                                    <th>临时措施得分</th>
                                    <th>纠正措施得分</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                </tbody>
                            </table>
                        </div>

                    </div>
                    <!-- /.panel-body -->

                </div>
                <!-- /.panel -->
            </div>
        </div>


    </div>
    <!-- /#page-wrapper -->

    <div class="modal fade" id="delModal" tabindex="-1" role="dialog" aria-labelledby="pwdModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title">删除提示</h4>
                </div>
                <div class="modal-body">
                    确定删除该反馈问题？
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="button" onclick="_questionList.fn.subDelInfo()" class="btn btn-primary">确定</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>

    <div class="modal fade" id="sendModal" tabindex="-1" role="dialog" aria-labelledby="pwdModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title">派发任务</h4>
                </div>
                <div class="modal-body" style="height: 100px">
                    <div style="margin-bottom: 10px;">
                        <label class="col-sm-3 control-label" style="margin-top: 5px">所属部门:</label>

                        <div class="col-sm-9">
                            <select id="sectionList" onchange="_questionList.fn.loadMemberList(1)" class="form-control" style="width: 200px;margin-bottom: 5px;">
                                <option value="">请选择所属部门</option>
                            </select>
                        </div>
                    </div>
                    <div>
                        <label class="col-sm-3 control-label" style="margin-top: 5px">责任人姓名:</label>
                        <div class="col-sm-5">
                            <select id="memberList" class="form-control" style="width: 200px;margin-bottom: 5px;">
                                <option value="">请选择责任人</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="button" onclick="_questionList.fn.subSendInfo()" class="btn btn-primary">确定</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>

    <div class="modal fade" id="closeModal" tabindex="-1" role="dialog" aria-labelledby="pwdModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title">关闭任务</h4>
                </div>
                <div class="modal-body" style="height: 420px">
                    <form id="closeForm" method="post" action="admin/question/closeInfo">
                        <input type="hidden" name="id" id="questionId"/>
                        <div class="form-group">
                            <label class="col-sm-4 control-label" style="margin-top: 7px;">纠正措施描述:</label>
                            <div class="col-sm-7" style="margin-bottom: 5px;">
                                <textarea cols="20" rows="4" class="form-control" style="resize: none;" name="descriptionFour" id="descriptionFour"></textarea>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-4 control-label" style="margin-top: 7px;">纠正措施判别得分:</label>
                            <div class="col-sm-7" style="margin-bottom: 5px;">
                                <input type="text" class="form-control" id="scoreEleven" name="scoreEleven" maxlength="11" placeholder="请输入纠正措施判别得分"/>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-4 control-label" style="margin-top: 7px;">纠正措施计算得分:</label>
                            <div class="col-sm-7" style="margin-bottom: 5px;">
                                <input type="text" class="form-control" id="scoreTwelve" name="scoreTwelve" maxlength="11" placeholder="请输入纠正措施计算得分"/>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-4 control-label" style="margin-top: 7px;">纠正措施实际得分:</label>
                            <div class="col-sm-7" style="margin-bottom: 5px;">
                                <input type="text" class="form-control" id="scoreThirteen" name="scoreThirteen" maxlength="11" placeholder="请输入纠正措施实际得分"/>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-4 control-label" style="margin-top: 7px;">纠正措施责任人所属部门:</label>

                            <div class="col-sm-7" style="margin-bottom: 5px;">
                                <select id="sectionThree" onchange="_questionList.fn.loadMemberList(2)" class="form-control" style="width: 200px;margin-bottom: 5px;">
                                    <option value="">请选择所属部门</option>
                                </select>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-4 control-label" style="margin-top: 7px;">纠正措施责任人姓名:</label>

                            <div class="col-sm-7" style="margin-bottom: 5px;">
                                <select id="memberListTwo" class="form-control" style="width: 200px;margin-bottom: 5px;">
                                    <option value="">请选择责任人</option>
                                </select>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-4 control-label" style="margin-top: 7px;">纠正措施计划完成日期:</label>
                            <div class="col-sm-7" style="margin-bottom: 5px;">
                                <input type="text" class="form-control input-append date form_datetime" style="width: 220px;" readonly id="planDateTwo" name="planDateTwo" maxlength="20" placeholder="请选择纠正措施计划完成日期"/>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-4 control-label" style="margin-top: 7px;">纠正措施实际关闭日期:</label>
                            <div class="col-sm-7">
                                <input type="text" class="form-control input-append date form_datetime" style="width: 220px;" readonly id="actualDateTwo" name="actualDateTwo" maxlength="20" placeholder="请选择纠正措施实际关闭日期"/>
                            </div>
                        </div>
                    </form>

                    <form id="tempForm" method="post" style="display: none" action="admin/export/importFeedback?type=${sessionScope.sessionMember.type}" enctype="multipart/form-data" class="form-horizontal" role="form">
                        <input type="file" name="feedback" id="feedback" data-rule="required" onchange="_questionList.fn.saveTempInfo()"/>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="button" onclick="_questionList.fn.subCloseInfo()" class="btn btn-primary">确定</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>
</div>
<!-- /#wrapper -->

<%@ include file="inc/footer.jsp" %>
</body>

<script type="text/javascript">
    var _questionList = {
        v: {
            id: "_questionList",
            list: [],
            dTable: null
        },
        fn: {
            init: function () {
                _questionList.fn.dataTableInit();

                $('.form_datetime').datetimepicker({
                    minView: "month", //选择日期后，不会再跳转去选择时分秒
                    format: "yyyy-mm-dd", //选择日期后，文本框显示的日期格式
                    language: 'zh-CN', //汉化
                    autoclose: true //选择日期后自动关闭
                });

                // 查询
                $("#c_search").click(function () {
                    _questionList.v.dTable.ajax.reload();
                });

                // 加载部门信息
                _questionList.fn.getSelectList();
            },
            clickFire: function () {
                $('#feedback').click();
            },
            saveTempInfo: function () {
                $("#tempForm").ajaxSubmit({
                    dataType: "json",
                    success: function (data) {
                        if (data == '1') {
                            $leoman.notify("上传成功", "success");
                            $('#feedback').val('');
                            _questionList.v.dTable.ajax.reload();
                        } else {
                            $leoman.notify("上传失败", "error");
                            $('#feedback').val('');
                        }
                    }
                });
            },
            dataTableInit: function () {
                _questionList.v.dTable = $leoman.dataTable($('#dataTables'), {
                    "processing": true,
                    "serverSide": true,
                    "searching": false,
                    "ordering": false,
                    "ajax": {
                        "url": "admin/question/list",
                        "type": "POST"
                    },
                    "columns": [
                        {"data": "id"},
                        {"data": "type.name"},
                        {"data": "recordDate"},
                        {
                            "data": "area",
                            render: function (data) {
                                if (null != data) {
                                    return data.name;
                                } else {
                                    return '';
                                }
                            }
                        },
                        {"data": "descriptionTwo"},
                        {"data": "scoreSeven"},
                        {"data": "nameOne"},
                        {"data": "sectionOne"},
                        {"data": "scoreTen"},
                        {"data": "scoreThirteen"},
                        {"data": ""}
                    ],
                    "columnDefs": [
                        {
                            "data": null,
                            "defaultContent": "<button type='button' title='编辑' style='margin-right: 8px;' class='btn btn-primary btn-circle edit'>" +
                            "<i class='fa fa-edit'></i>" +
                            "</button>" +
                            "<button type='button' title='删除' style='margin-right: 8px;' class='btn btn-danger btn-circle delete'>" +
                            "<i class='fa fa-remove'></i>" +
                            "</button>" +
                            "<button type='button' title='派发任务' style='display: none;margin-right: 8px;' class='btn btn-info btn-circle send'>" +
                            "<i class='fa fa-send'></i>" +
                            "</button>" +
                            "<button type='button' title='关闭任务' style='display: none;margin-right: 8px;' class='btn btn-warning btn-circle closed'>" +
                            "<i class='fa fa-reply'></i>" +
                            "</button>",
                            "targets": -1
                        }
                    ],
                    "createdRow": function (row, data, index) {
                        _questionList.v.list.push(data);

                        if (null != data.descriptionTwo && data.descriptionTwo != '') {
                            if (data.descriptionTwo.length > 20) {
                                $('td', row).eq(4).html((data.descriptionTwo).substring(0, 20) + '...');
                            } else {
                                $('td', row).eq(4).html(data.descriptionTwo);
                            }
                        } else {
                            $('td', row).eq(4).html('');
                        }
                    },
                    rowCallback: function (row, data) {
                        if (data.status == 0) {
                            $('td', row).last().find(".send").css('display', '');
                        }

                        if (data.status == 1) {
                            $('td', row).last().find(".closed").css('display', '');
                        }

                        $('td', row).last().find(".edit").click(function () {
                            window.location.href = '${contextPath}/admin/question/show?id=' + data.id;
                        });

                        $('td', row).last().find(".delete").click(function () {
                            _questionList.fn.delInfo(data.id);
                        });

                        $('td', row).last().find(".send").click(function () {
                            _questionList.fn.sendInfo(data.id);
                        });

                        $('td', row).last().find(".closed").click(function () {
                            _questionList.fn.closeInfo(data.id);
                        });
                    },
                    "fnServerParams": function (aoData) {
                        aoData.typeId = $('#typeList option:selected').val();
                    },
                    "fnDrawCallback": function (row) {
                        $leoman.uiform();
                    }
                });
            },
            getSelectList: function () {
                $leoman.ajax("admin/sectionList", null, function (result) {
                    if (null != result) {
                        // 获取返回的部门信息，并循环绑定到label中
                        var content = "";
                        jQuery.each(result, function (i, item) {
                            content += "<option value='" + item.id + "'>" + item.name + "</option>";
                        });
                        $('#sectionList').append(content);
                        $('#sectionThree').append(content);
                    } else {
                        $leoman.notify("获取部门信息失败", "error");
                    }
                });
            },
            loadMemberList: function (flag) {
                $('#memberList').html('');
                $('#memberListTwo').html('');
                var contactId = null;
                if (flag == 1) {
                    contactId = $('#sectionList option:selected').val();
                } else {
                    contactId = $('#sectionThree option:selected').val();
                }

                // 获取返回的部门人员信息，并循环绑定到label中
                var content = "<option value=''>请选择责任人</option>";
                if (null != contactId && contactId != '') {
                    $leoman.ajax("admin/memberList", {
                        contactId: contactId
                    }, function (result) {
                        if (null != result) {
                            jQuery.each(result, function (i, item) {
                                content += "<option value='" + item.id + "'>" + item.name + "</option>";
                            });
                            $('#memberList').append(content);
                            $('#memberListTwo').append(content);
                        } else {
                            $leoman.notify("获取部门人员信息失败", "error");
                        }
                    });
                } else {
                    $('#memberList').append(content);
                    $('#memberListTwo').append(content);
                }
            },
            delInfo: function (id) {
                $('#questionId').val(id);
                $("#delModal").modal("show");
            },
            subDelInfo: function () {
                var questionId = $('#questionId').val();

                $leoman.ajax("admin/question/delete", {
                    "id": questionId
                }, function (result) {
                    if (result == 1) {
                        $leoman.notify("操作成功", "success");
                        $("#delModal").modal("hide");
                        _questionList.v.dTable.ajax.reload(null, false);
                    } else {
                        $leoman.notify("操作失败", "error");
                    }
                });
            },
            sendInfo: function (id) {
                $('#questionId').val(id);
                $("#sendModal").modal("show");
            },
            subSendInfo: function () {
                var questionId = $('#questionId').val();
                var section = $('#sectionList option:selected').val();
                var name = $('#memberList option:selected').val();
                var namePlus = '';

                if (null == section || section == '') {
                    $leoman.notify('请选择所属部门', "error");
                    return false;
                }

                if (null != name && name != '') {
                    namePlus = $('#memberList option:selected').text();
                }

                $leoman.ajax("admin/question/sendInfo", {
                    "id": questionId,
                    "section": $('#sectionList option:selected').text(),
                    "name": namePlus,
                    "sectionId": section,
                    "userId": name
                }, function (result) {
                    if (result == 1) {
                        $leoman.notify("操作成功", "success");
                        $("#sendModal").modal("hide");
                        _questionList.v.dTable.ajax.reload(null, false);
                    } else {
                        $leoman.notify("操作失败", "error");
                    }
                });
            },
            closeInfo: function (id) {
                $('#questionId').val(id);
                $("#closeModal").modal("show");
            },
            subCloseInfo: function () {
                var descriptionFour = $('#descriptionFour').val();
                var scoreEleven = $('#scoreEleven').val();
                var scoreTwelve = $('#scoreTwelve').val();
                var scoreThirteen = $('#scoreThirteen').val();
                var nameThree = $('#memberListTwo option:selected').val();
                var sectionThree = $('#sectionThree option:selected').val();
                var planDateTwo = $('#planDateTwo').val();
                var actualDateTwo = $('#actualDateTwo').val();

                if (null == descriptionFour || descriptionFour == '') {
                    $leoman.notify('请输入纠正措施描述', "error");
                    return false;
                }

                if (null == scoreEleven || scoreEleven == '') {
                    $leoman.notify('请输入纠正措施实际得分', "error");
                    return false;
                }

                if (Math.floor(scoreEleven) != scoreEleven) {
                    $leoman.notify('纠正措施实际得分须为整数', "error");
                    return false;
                }

                if (null == scoreTwelve || scoreTwelve == '') {
                    $leoman.notify('请输入纠正措施实际得分', "error");
                    return false;
                }

                if (Math.floor(scoreTwelve) != scoreTwelve) {
                    $leoman.notify('纠正措施实际得分须为整数', "error");
                    flag = false;
                    return;
                }

                if (null == scoreThirteen || scoreThirteen == '') {
                    $leoman.notify('请输入纠正措施实际得分', "error");
                    return false;
                }

                if (Math.floor(scoreThirteen) != scoreThirteen) {
                    $leoman.notify('纠正措施实际得分须为整数', "error");
                    return false;
                }

                if (null == nameThree || nameThree == '') {
                    $leoman.notify('请输入纠正措施责任人姓名', "error");
                    return false;
                }

                if (null == sectionThree || sectionThree == '') {
                    $leoman.notify('请选择纠正措施责任人所属部门', "error");
                    return false;
                }

                if (null == planDateTwo || planDateTwo == '') {
                    $leoman.notify('请选择纠正措施计划完成日期', "error");
                    return false;
                }

                if (null == actualDateTwo || actualDateTwo == '') {
                    $leoman.notify('请选择纠正措施实际关闭日期', "error");
                    return false;
                }

                $("#closeForm").ajaxSubmit({
                    dataType: "json",
                    data: {
                        sectionThree: $('#sectionThree option:selected').text(),
                        nameThree: $('#memberListTwo option:selected').text()
                    },
                    success: function (result) {
                        if (result == 1) {
                            $leoman.notify("操作成功", "success");
                            $("#closeModal").modal("hide");
                            _questionList.v.dTable.ajax.reload(null, false);
                        } else {
                            $leoman.notify("操作失败", "error");
                        }
                    }
                });
            },
            toDownloadExcel: function () {
                window.location.href = '${contextPath}/admin/export/exportFeedback?typeId=' + $('#typeList option:selected').val();
            }
        }
    }

    $(document).ready(function () {
        _questionList.fn.init();
    });

</script>

</html>